- bulk_imports_disabled = !Gitlab::CurrentSettings.bulk_import_enabled?

= gitlab_ui_form_with url: configure_import_bulk_imports_path(namespace_id: params[:parent_id]), class: 'gl-show-field-errors' do |f|
  .gl-border-l-solid.gl-border-r-solid.gl-border-t-solid.gl-border-gray-100.gl-border-1.gl-p-5.gl-mt-4
    .gl-display-flex.gl-align-items-center
      %h4.gl-display-flex
        = s_('GroupsNew|Import groups by direct transfer')
      = link_to _('History'), history_import_bulk_imports_path, class: 'gl-link gl-ml-auto'

    - if bulk_imports_disabled
      = render Pajamas::AlertComponent.new(dismissible: false, variant: :tip) do |c|
        - c.with_body do
          = s_('GroupsNew|Importing groups by direct transfer is currently disabled.')

          - if current_user.admin?
            - admin_link_start = '<a href="%{url}">'.html_safe % { url: general_admin_application_settings_path(anchor: 'js-visibility-settings') }
            - admin_link_end = '</a>'.html_safe

            = s_('GroupsNew|Please %{admin_link_start}enable it in the Admin settings%{admin_link_end}.').html_safe % { admin_link_start: admin_link_start, admin_link_end: admin_link_end }
          - else
            = s_('GroupsNew|Please ask your Administrator to enable it in the Admin settings.')

          = s_('GroupsNew|Remember to enable it also on the instance you are migrating from.')
    - else
      = render Pajamas::AlertComponent.new(dismissible: false,
        variant: :warning) do |c|
        - c.with_body do
          - docs_link_start = '<a href="%{url}" target="_blank" rel="noopener noreferrer">'.html_safe % { url: help_page_path('user/group/import/index.md', anchor: 'migrated-group-items') }
          - docs_link_end = '</a>'.html_safe
          = s_('GroupsNew|Not all group items are migrated. %{docs_link_start}What items are migrated%{docs_link_end}?').html_safe % { docs_link_start: docs_link_start, docs_link_end: docs_link_end }

    %p.gl-mt-3
    = s_('GroupsNew|Provide credentials for the source instance to import from. You can provide this instance as a source to move groups in this instance.')
    .form-group.gl-display-flex.gl-flex-direction-column
      = f.label :bulk_import_gitlab_url, s_('GroupsNew|GitLab source instance URL'), for: 'import_gitlab_url'
      = f.text_field :bulk_import_gitlab_url, disabled: bulk_imports_disabled, placeholder: 'https://gitlab.example.com', class: 'gl-form-input col-xs-12 col-sm-8',
        required: true,
        title: s_('GroupsNew|Enter the URL for the source instance.'),
        id: 'import_gitlab_url',
        data: { qa_selector: 'import_gitlab_url' }
    .form-group.gl-display-flex.gl-flex-direction-column
      = f.label :bulk_import_gitlab_access_token, s_('GroupsNew|Personal access token'), for: 'import_gitlab_token'
      .gl-font-weight-normal
        - pat_link_start = '<a href="%{url}" target="_blank">'.html_safe % { url: help_page_path('user/profile/personal_access_tokens') }
        - short_living_link_start = '<a href="%{url}" target="_blank">'.html_safe % { url: help_page_path('security/token_overview', anchor: 'security-considerations') }
        = s_('GroupsNew|Create a token with %{code_start}api%{code_end} and %{code_start}read_repository%{code_end} scopes in the %{pat_link_start}user settings%{pat_link_end} of the source GitLab instance. For %{short_living_link_start}security reasons%{short_living_link_end}, set a short expiration date for the token. Keep in mind that large migrations take more time.').html_safe % { code_start: '<code>'.html_safe, code_end: '</code>'.html_safe, pat_link_start: pat_link_start, pat_link_end: '</a>'.html_safe, short_living_link_start: short_living_link_start, short_living_link_end: '</a>'.html_safe }
      = f.text_field :bulk_import_gitlab_access_token, placeholder: s_('GroupsNew|e.g. h8d3f016698e...'), class: 'gl-form-input gl-mt-3 col-xs-12 col-sm-8',
        required: true,
        disabled: bulk_imports_disabled,
        autocomplete: 'off',
        title: s_('GroupsNew|Please fill in your personal access token.'),
        id: 'import_gitlab_token',
        data: { qa_selector: 'import_gitlab_token' }
  .gl-border-gray-100.gl-border-solid.gl-border-1.gl-bg-gray-10.gl-p-5
    = f.submit s_('GroupsNew|Connect instance'), disabled: bulk_imports_disabled, pajamas_button: true, data: { qa_selector: 'connect_instance_button' }
